package nyist.media.controller;

import nyist.media.page.ApiResult;
import nyist.media.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping(value = "admin/teachers")
@ResponseBody
@RestController
public class TeacherController extends BaseController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 分页查询教师列表
     *
     * @param page    页码
     * @param limit   页长
     * @param keyword 搜索关键字
     * @return 教师列表
     */
    @GetMapping
    public Map<String, Object> showTeachers(Integer page, Integer limit, String keyword) {
        PageRequest pageRequest = new PageRequest(page - 1, limit);
        return toResultPage(teacherService.findPage(pageRequest, keyword));
    }

    /**
     * 查看提交的维修单详情
     */
    @GetMapping("/{id}/apply_orders")
    public Map<String, Object> showApplyOrders(@PathVariable Long id, Integer page, Integer limit) {
        PageRequest pageRequest = new PageRequest(page - 1, limit);
        return toResultPage(teacherService.findApplyOrders(pageRequest, id));
    }
}
